<template>
  <a-modal
    title="添加業主"
    :width="600"
    class="model-yz"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false"><a-input  v-decorator="['id']" /></a-form-item>
        <a-form-item
          label="賬號類型"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="請選擇賬號類型"  v-decorator="['accountType', { initialValue: '1' }]"  @change="bankChange">
            <a-select-option v-for="(item,index) in accountTypeData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="持卡人"
          v-show="bankDisabled"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="請輸入持卡人" v-decorator="['cardHolder']" />
        </a-form-item>
        <a-form-item
          label="卡號"
          v-show="bankDisabled"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="請輸入卡號" v-decorator="['cardNumber']" />
        </a-form-item>
        <a-form-item
          label="開戶銀行"
          v-show="bankDisabled"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="請選擇開戶銀行"  v-decorator="['cardBankType']">
            <a-select-option v-for="(item,index) in cardBankTypeData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="賬號"
           v-show="!bankDisabled"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol">
          <a-input placeholder="請輸入賬號" v-decorator="['account']" />
        </a-form-item>
        <a-form-item
          label="收款人"
           v-show="!bankDisabled"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol">
          <a-input placeholder="請輸入收款人" v-decorator="['payee']" />
        </a-form-item>
        <a-form-item
          label="交租提醒"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-radio-group  v-decorator="['rentReminderSwitch', { initialValue: 1 }]" @change="rentReminderSwitchChange">
            <a-radio :value="1">開啟</a-radio>
            <a-radio :value="0">關閉</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
            v-show="onRentReminderSwitch"
                  label="收租提醒提前 天"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                >
                  <a-select  style="width: 100%" v-decorator="['rentReminderDay', { initialValue: 0 }]">
                    <a-select-option  style="width: 100%"  :value="0">當天</a-select-option>
                    <a-select-option  style="width: 100%"  v-for="(item,index) in 30" :key="index" :value="item">{{ item }}天</a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  v-show="false"
                  label="收租提醒提前 小時"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol">
                  <a-select  style="width: 100%" v-decorator="['rentReminderHour', { initialValue: 0 , rules: [{ required: true, message: '请选择收租提醒提前 小時！' }]}]">
                    <a-select-option  style="width: 100%"   :key="0" :value="0">0點</a-select-option>
                    <a-select-option  style="width: 100%"  v-for="(item,index) in 23" :key="index" :value="item">{{ item }}點</a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  v-show="false"
                  label="收租提醒提前 分鐘"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol">
                  <a-select  style="width: 100%" v-decorator="['rentReminderMinutes', { initialValue: 0 , rules: [{ required: true, message: '请选择收租提醒提前 分鐘！' }]}]">
                    <a-select-option  style="width: 100%"  :key="0" :value="0">0分</a-select-option>
                    <a-select-option  style="width: 100%"  v-for="(item,index) in 59" :key="index" :value="item">{{ item }}分</a-select-option>
                  </a-select>
                </a-form-item>
            <a-form-item
                  label="备注"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol">
                  <a-textarea placeholder="请输入備注" v-decorator="['remark']" />
            </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { ownerLeaseEditTxxxAndAc } from '@/api/modular/main/ownerlease/ownerLeaseManage'
  export default {
     components: {
    },
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        memberLoading: false,
        form: this.$form.createForm(this),
        cardBankTypeData: [],
        accountTypeData: [],
        bankDisabled: true,
        onRentReminderSwitch: true
      }
    },
    methods: {
      // 初始化方法
      edit (record) {
        this.visible = true
        this.bankChange(record.accountType + '')
        if (record.rentReminderSwitch !== 1) {
          this.onRentReminderSwitch = false
        }
        const accountTypeOption = this.$options
        this.accountTypeData = accountTypeOption.filters['dictData']('account_type')
        const cardBankTypeOption = this.$options
        this.cardBankTypeData = cardBankTypeOption.filters['dictData']('card_bank_type')
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              id: record.id,
              accountType: record.accountType + '',
              cardHolder: record.cardHolder,
              cardNumber: record.cardNumber,
              cardBankType: record.cardBankType,
              account: record.account,
              payee: record.payee,
              rentReminderSwitch: record.rentReminderSwitch,
              rentReminderDay: record.rentReminderDay,
              rentReminderHour: record.rentReminderHour,
              rentReminderMinutes: record.rentReminderMinutes,
              remark: record.remark
            }
          )
        }, 100)
      },
      bankChange(value) {
        if (value === '1') {
          this.bankDisabled = true
        } else {
          this.bankDisabled = false
        }
      },
      rentReminderSwitchChange() {
        this.onRentReminderSwitch = !this.onRentReminderSwitch
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            ownerLeaseEditTxxxAndAc(values).then((res) => {
              if (res.code === 200) {
                this.$message.success('修改成功')
                this.confirmLoading = false
                this.$emit('ok', '')
                this.handleCancel()
              } else {
                this.$message.error(res.msg)// + res.message
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
        this.bankDisabled = true
        this.onRentReminderSwitch = true
      }
    }
  }
</script>
<style lang="less" scoped >
/* you can make up upload button and sample style by using stylesheets */
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
.parImg{
  position: relative;
}
.parImg_icon{
  position: absolute;
  top: 0;
  right: 0;
  color: rgba(255, 0, 0, 0.829);
}
.mocheck{
  background-color: rgba(58, 136, 180, 0.822);
  color: aliceblue;
}
</style>
